package com.kukudb.asaproject.pojo;

import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;

import java.io.Serializable;


@Data
public class ResponseMessage<T>  {
    private Integer code;
    private String message;
    private T data;

//    Logger logger = LoggerFactory.getLogger(ResponseMessage.class);
    public ResponseMessage(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResponseMessage(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    public static <T> ResponseMessage<T> success(T data) {
        return new ResponseMessage<>(HttpStatus.OK.value(), "success", data);
    }
    public static <T> ResponseMessage<T> error(T data) {
        return new ResponseMessage<>(500, "error",data);
    }


    public String toJson() {
        return "{\"code\":" + code + ",\"message\":\"" + message + "\",\"data\":" + data + "}";
    }
}
